package com.weixing.oauth2.common.authorize;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: kfc
 * @Description: <br/>
 * Date:Create in 2019/8/13 14:06
 * @Modified By:
 */
@Component
public class AuthorizeCheck {

    private AntPathMatcher antPathMatcher = new AntPathMatcher();

    public boolean hasPermission(Authentication authentication, HttpServletRequest request){
return true;
        // 判断
//        String requestURI = request.getRequestURI();
//        Object principal = authentication.getPrincipal();
//        boolean hasPermission = false;
//        if(principal instanceof UserDetails) {
//            String username = ((UserDetails) principal).getUsername();
//            // 读取用户所拥有的权限url，这里应该从数据库获取
//            Set<String> urls = new HashSet<>();
//            Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
//
//            for (GrantedAuthority url : authorities) {
//                // 判断当前url是否有权限
//                if(antPathMatcher.match(url.getAuthority(), requestURI)) {
//                    hasPermission = true;
//                    break;
//                }
//            }
//        }
//        return hasPermission;
    }

}
